// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  // const wxContext = cloud.getWXContext()

  // return {
  //   event,
  //   openid: wxContext.OPENID,
  //   appid: wxContext.APPID,
  //   unionid: wxContext.UNIONID,
  // }

  const templateId = '5E2kzq-gqu8UE6bB89slTl8YEBp_qz6ou8vGCQt0xUk'
  try {
    const result = await cloud.openapi.subscribeMessage.send({
        "touser": event.openid,
        "page": 'pages/index/index',
        "lang": 'zh_CN',
        "data": {
          "thing1": {
            "value": event.taskName
          },
          "time7": {
            "value": event.remindTime
          }
        },
        "templateId": templateId,
        "miniprogramState": 'developer'
      })
    return result
  } catch (err) {
    return err
  }
}